<template>
 <div>
   <!-- 面包屑 -->
   <el-breadcrumb separator="/">
     <el-breadcrumb-item :to="{ path: '/Welcome' }">首页</el-breadcrumb-item>
     <el-breadcrumb-item>订单管理</el-breadcrumb-item>
     <el-breadcrumb-item>订单列表</el-breadcrumb-item>
   </el-breadcrumb>
   <!-- 卡片 -->
   <el-card>
     <!-- 搜索框 -->
     <el-input placeholder="请输入内容" v-model="queryData.query" class="input-with-select" style="width: 600px">
       <el-button slot="append" icon="el-icon-search" @click="searchOrder"></el-button>
     </el-input>
     <!-- 表格 -->
     <el-table
       :data="orderList"
       border
        style="width: 100%">
        <el-table-column type="index" label="#"></el-table-column>
        <el-table-column
         prop="order_number"
         label="订单编号"
         width="500">
       </el-table-column>
       <el-table-column
         prop="order_price"
         label="订单价格"
       >
       </el-table-column>
       <el-table-column prop="pay_status" label="是否付款">
         <template slot-scope="scope">
           <el-tag type="success" v-if="scope.row.pay_status=== 1">已支付</el-tag>
           <el-tag type="warning" v-else>未支付</el-tag>
         </template>
       </el-table-column>
       <el-table-column prop="is_send" label="是否发货"></el-table-column>
       <el-table-column prop="create_time" label="下单时间">
         <template slot-scope="scope">
           {{ scope.row.create_time | dateFormat }}
         </template>
       </el-table-column>
       <el-table-column prop="address" label="操作">
         <template>
           <el-button type="primary" size="mini" @click="addressDialogVisible=true">修改地址</el-button>
           <el-button type="success" size="mini" @click="openExpressDialog">查看物流</el-button>
         </template>
       </el-table-column>
    </el-table>
    <!-- 分页  -->
    <el-pagination
      @size-change="handleSizeChange"
      @current-change="handleCurrentChange"
      :current-page="queryData.pagenum"
      :page-sizes="[5, 10, 15, 20]"
      :page-size="queryData.pagesize"
      layout="total, sizes, prev, pager, next, jumper"
      :total="total">
    </el-pagination>
   </el-card>
   <!-- 修改地址对话栏 -->
   <el-dialog
     title="提示"
     :visible.sync="addressDialogVisible"
     width="50%"
   >
      <el-form ref="form" :model="addressForm" label-width="80px">
        <el-form-item label="省市区/县">
          <el-cascader
            v-model="addressForm.cascAddress"
            :options="address"
            :props="{ expandTrigger: 'hover' }"
            @change="addressHandleChange">
            </el-cascader>
        </el-form-item>
        <el-form-item label="活动名称">
          <el-input></el-input>
        </el-form-item>
      </el-form>
     <span slot="footer" class="dialog-footer">
        <el-button @click="addressDialogVisible = false">取 消</el-button>
        <el-button type="primary" @click="addressDialogVisible = false">确 定</el-button>
      </span>
    </el-dialog>
    <!-- 查看物流进度对话框 -->
       <el-dialog
     title="物流进度"
     :visible.sync="logisticsDialogVisible"
     width="50%"
   >
      <el-timeline :reverse="true">
        <el-timeline-item
          v-for="(item, index) in expressList"
          :key="index"
          :timestamp="item.time">
          {{item.content}}
        </el-timeline-item>
      </el-timeline>
    </el-dialog>
 </div>
</template>

<script>
import address from './citydata.js'
export default {
  data () {
    return {
      // 页码
      queryData: {
        query: '',
        pagenum: 1,
        pagesize: 5
      },
      total: 0,
      orderList: [],
      addressDialogVisible: false,
      logisticsDialogVisible: false,
      addressForm: {
        cascAddress: []
      },
      address,
      // 物流数据
      expressList: []
    }
  },
  created () {
    this.getOrderList()
  },
  methods: {
    // 获取订单数据列表
    async getOrderList () {
      const { data: res } = await this.$axios.get('orders', {
        params: this.queryData
      })
      if (res.meta.status !== 200) return this.$message.error('获取订单列表失败')
      this.orderList = res.data.goods
      this.total = res.data.total
    },
    // 分页
    handleSizeChange (pagesize) {
      this.queryData.pagesize = pagesize
      this.getOrderList()
    },
    handleCurrentChange (pagenum) {
      this.queryData.pagenum = pagenum
      this.getOrderList()
    },
    // 搜索指定订单数据
    searchOrder () {
      this.getOrderList()
    },
    // 级联选择器选中时的事件
    addressHandleChange () {
      console.log(this.addressForm.cascAddress)
    },
    // openExpressDialog  打开查看物流对话框  发起请求获取我留数据
    async openExpressDialog () {
      this.logisticsDialogVisible = true
      // 接口未处理跨域,需要代理服务器
      // 将请求接口前拼接上自己项目跑在的端口上
      const { data: res } = await this.$axios.get('http://localhost:8080/api/express')
      this.expressList = res.data
    }
  }
}
</script>

<style scoped>

</style>
